<?php
/**
* 名称：内参资讯模型类。
* 描述：内参资讯模块业务逻辑的相关程式。
*/
final class Model_IRRS extends Model{
    /**
    * 描述：供给数据之最新信息。
    * @static
    * @access public
    * @return array
    */
    public static function GetDataX0001($count=10){
        $data=self::MakeLinkForDetail(self::$Database->GetAll(
            'SELECT * FROM '.self::$Database->Table('irrs').' ORDER BY datetime DESC LIMIT 0,'.$count
        ));
        //~
        $struct=array(
            'top'=>$data,
        );
        if(!empty($data)&&count($data)>1){
            $struct=array(
                'top'=>$data[0],
                'common'=>array_slice($data,1,count($data)),
            );
        }
        //~
        return array(
            'Name'=>'内参资讯',
            'Link'=>Route::MakeHyperlink(':irrs::listview'),
            'Rows'=>$struct
        );
    }

    /**
    * 描述：供给数据之行业动态。
    * @static
    * @access public
    * @return array
    */
    public static function GetDataX0002(){
        $class=45;
        return array(
            'Name'=>'行业动态',
            'Link'=>Route::MakeHyperlink(':irrs::listview',array('class'=>$class)),
            'Rows'=>self::GetRowsByClass($class)
        );
    }

    /**
    * 描述：供给数据之丛类数据。
    * @static
    * @access public
    * @return array
    */
    public static function GetDataX0003(){
        $data=self::MakeLinkForListview(self::$Database->GetAll(
            'SELECT * FROM '.self::$Database->Table('irrs_class').' ORDER BY id ASC'
        ));
        return array('Name'=>'内参资讯','Link'=>Route::MakeHyperlink(':irrs'),'Rows'=>$data);
    }

    /**
    * 描述：完备数据之详细。
    * @static
    * @access public
    * @return array
    */
    public static function MakeLinkForDetail($data){
        foreach($data as &$row){
            $row['link']=Route::MakeHyperlink(':irrs::detail',array('id'=>$row['id']));
            $row['cover']=BUILD_PATH.'/data/000/news/'.$row['cover'];
            $purifier=new HTMLPurifier(HTMLPurifier_Config::createDefault());
            $row['summary']=$purifier->purify($row['content']);
        }
        return $data;
    }

    /**
    * 描述：完备数据之列表。
    * @static
    * @access public
    * @return array
    */
    public static function MakeLinkForListview($data){
        foreach($data as &$row){
            $row['link']=Route::MakeHyperlink(':irrs::listview',array('class'=>$row['id']));
        }
        return $data;
    }

    /**
    * 描述：返回数据之按丛类。
    * @static
    * @access protected
    * @return array
    */
    protected static function GetRowsByClass($class,$count=10){
        $table=self::$Database->Table('irrs');
        //~
        $data=self::$Database->GetAll(
            'SELECT * FROM '.$table.' WHERE class='.$class.' ORDER BY datetime DESC LIMIT 0,'.$count
        );
        //~
        return self::MakeLinkForDetail($data);
    }
}